import { defineStore } from 'pinia';
import RequestService from '@/service/RequestService.ts';
import PromiseUtils from '@/utils/PromiseUtils.ts';
import { UserInfoVO } from '@/entiy/vo/UserInfoVO.ts';

export const useSystemSettingComponentStore = defineStore('systemSettingComponentStore', {
    state: () => {
        return {
            showSystemSetting: false,
        };
    },

    getters: {

    },

    actions: {

        /**
         * 更新用户头像
         *
         * @param file 用户头像文件
         */
        async uploadUserImage(file: File): Promise<UserInfoVO> {
            try {
                // 构建 FormData 对象
                const formData = new FormData();
                formData.append('uploadFile', file);

                // 上传文件
                const bizResult = await RequestService.updateFile<UserInfoVO>('/user-manage/update-user-image', formData);
                if (bizResult.isError) {
                    return PromiseUtils.reject(bizResult.errorMsg);
                }
                return PromiseUtils.resolveValue(bizResult.bizDta);
            } catch (e) {
                return PromiseUtils.rejectSystemError();
            }
        }
    }
});